﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using V2.PaidTimeOffBLL.Framework;

public partial class Administration_Users : BasePage
{
    private const int COL_INDEX_ACTION = 0;
    private const int COL_INDEX_NAME = 1;
    private const int COL_INDEX_WINDOWSNAME = 2;
    private const int COL_INDEX_EMAIL = 3;
    private const int COL_INDEX_ACTIVE = 4;

    protected void Page_Load(object sender, EventArgs e)
    {
        Master.AddButton_Click += new PaidTimeOffEditGrid.ButtonClickedHandler(Master_AddButton_Click);

        if (!IsPostBack)
        {
            //Tell the control what class to create and what method to call to load the class.
            cgvUsers.ListClassName = typeof(ENTUserAccountEOList).AssemblyQualifiedName;
            cgvUsers.LoadMethodName = "Load";

            //Action column-Contains the Edit link
            cgvUsers.AddBoundField("", "Actions", "");

            //Name
            cgvUsers.AddBoundField("DisplayText", "Name", "DisplayText");

            //Windows Account Name
            cgvUsers.AddBoundField("WindowsAccountName", "Windows Account", "WindowsAccountName");

            //Email
            cgvUsers.AddBoundField("Email", "Email", "Email");

            //Is Active-This will be a checkbox column
            cgvUsers.AddBoundField("", "Active", "IsActive");

            cgvUsers.DataBind();            
        }
    }

    void Master_AddButton_Click(object sender, EventArgs e)
    {
        Response.Redirect("User.aspx" + EncryptQueryString("id=0"));
    }

    public override string MenuItemName()
    {
        return "Users";
    }

    protected void cgvUsers_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //Add the edit link to the action column.
            HyperLink editLink = new HyperLink();

            if (((BasePage)this.Page).ReadOnly)
            {
                editLink.Text = "View";
            }
            else
            {
                editLink.Text = "Edit";
            }

            editLink.NavigateUrl = "User.aspx" + EncryptQueryString("id=" + ((ENTUserAccountEO)e.Row.DataItem).ID.ToString());

            e.Row.Cells[COL_INDEX_ACTION].Controls.Add(editLink);

            //Add checkbox to display the isactive field.
            CheckBox chkActive = new CheckBox();
            chkActive.Checked = ((ENTUserAccountEO)e.Row.DataItem).IsActive;
            chkActive.Enabled = false;

            e.Row.Cells[COL_INDEX_ACTIVE].Controls.Add(chkActive);
        }
    }

    public override string[] CapabilityNames()
    {
        return new string[] { "Users" };
    }        
}
